package com.springboot.demo.controller;


import com.cx.item.common.vo.ResultPageVo;
import com.github.pagehelper.PageInfo;
import com.springboot.demo.model.model.Demo;
import com.springboot.demo.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by h on 2018/5/6.
 */
@Api(description = "demo演示类")
@Controller
@RequestMapping("/demo")
@Slf4j
public class DemoController {

    @Value("${demo.public.key1}")
    private String demoPublicKey1;

    @Autowired
    private DemoService demoService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @ApiOperation("分页查询")
    @RequestMapping(value = "/getPageList", method = RequestMethod.GET)
    @ResponseBody
    public ResultPageVo<PageInfo<Demo>> getPageList(Demo demo) {

        log.info(demoPublicKey1);
        String s = redisTemplate.opsForValue().get(demo.getName());
        log.info(s);

        log.info("aaaaaaaaaaaaaaaaaaaaa");
        log.debug("bbbbbbbbbbbbbbbbbbbbb");
        PageInfo<Demo> pageTestList = demoService.getPageList(demo.getPageNum(), demo.getPageSize(), demo);

        return ResultPageVo.success(pageTestList);
    }

    @ApiOperation("添加")
    @RequestMapping(value = "/addDemo", method = RequestMethod.POST)
    @ResponseBody
    public ResultPageVo addDemo(Demo demo) {
        int i = demoService.insertSelective(demo);

        return ResultPageVo.success(i);
    }

    @ApiOperation("获取")
    @RequestMapping(value = "/getDemoById", method = RequestMethod.GET)
    @ResponseBody
    public ResultPageVo<Demo> getDemoById(Integer id) {

        Demo demo = demoService.selectByPrimaryKey(id);

        return ResultPageVo.success(demo);
    }
}
